# filename:yangsy.py
# -*- coding: UTF-8 -*-

from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.common.exceptions import TimeoutException
import time

url = 'https://test.rabbitpre.com/'
driver = webdriver.Chrome()
driver.get(url)
driver.maximize_window()

# 登录：
sign_btn = driver.find_element_by_xpath('//*[@id="g-j-signin-btn"]')
sign_btn.click()
login_sso = driver.find_element_by_id('sso')
driver.switch_to.frame(login_sso)
driver.find_element_by_xpath('/html/body/div[1]/div/div[2]/div[1]/span[2]')
time.sleep(2)
account = driver.find_element_by_css_selector('div.tab-container span[data-type="tuzhan"]')
account.click()
driver.find_element_by_css_selector('input[type="text"]').send_keys('xxx')
driver.find_element_by_css_selector('div.password.form-password input[placeholder="请输入密码"]').send_keys('xxx')
driver.find_element_by_css_selector('button[class="g-btn login-btn do-btn"]').click()
time.sleep(2)

try:
    login = WebDriverWait(driver,10,0.5).until_not(lambda x: x.find_element_by_css_selector('div.login-form span.error-tips'))
except TimeoutException:
    driver.get_screenshot_as_file('login_error.png')
else:
    print('login success')

driver.quit()